<style lang="less">
@import "./login.less";
</style>

<template>
  <div class="login">
    <div class="login-con">
      <login-form @on-success-valid="handleSubmit"></login-form>
      <p class="login-tip">输入任意用户名和密码即可</p>
      <!-- <Card icon="log-in" title="欢迎登录" :bordered="false">
        <div class="form-con">


        </div>
      </Card> -->
    </div>
  </div>
</template>

<script>
import Main from "@/components/main";
import parentView from "@/components/parent-view";
import LoginForm from "_c/login-form";
import { mapActions } from "vuex";
import { resource_tree_auth } from "@/api/role";
export default {
  components: {
    LoginForm
  },
  methods: {
    ...mapActions(["handleLogin", "setUserInfo"]),
    handleSubmit({ userName, password }) {
      let that=this;
      this.handleLogin({ userName, password }).then(res => {
        if (res.code === 0) {
          this.setUserInfo(res.data);
          localStorage.setItem("tk", res.data.token.accessToken);
          localStorage.setItem("recordUserId", res.data.id);
          localStorage.setItem("recordUserName", res.data.trueName);
          resource_tree_auth({ id: res.data.id }).then(res => {
            if (res.code == 0) {
              let map1 = [];
              res.data.map(x => {
                if (x.children) {
                  for (let i = 0; i < x.children.length; i++) {
                    if (x.children[i].assigned == false) {
                      map1.push(x.children[i].handler);
                    }
                  }
                }
              });
              var newroutes = [
                {
                  path: "/",
                  name: "home",
                  meta: {
                    hideInBread: true,
                    title: "电厂级首页",
                    hideInMenu: isShow("/")
                  },
                  component: Main,
                  children: [
                    {
                      path: "/",
                      name: "home",
                      meta: {
                        icon: "md-home",
                        title: "电厂级首页"
                      },
                      component: () => import("@/view/single-page/home")
                    }
                  ]
                },
                {
                  path: "/home2",
                  name: "机组级首页",
                  meta: {
                    hideInBread: true,
                    hideInMenu: true
                  },
                  component: Main,
                  children: [
                    {
                      path: "/home2",
                      name: "机组级首页",
                      meta: {
                        icon: "md-home",
                        title: "机组级首页",
                        hideInMenu: isShow("/home2")
                      },
                      component: () => import("@/view/single-page/home/home2")
                    }
                  ]
                },
                {
                  path: "/message",
                  name: "message",
                  component: Main,
                  meta: {
                    hideInBread: true,
                    hideInMenu: true
                  },
                  children: [
                    {
                      path: "message_page",
                      name: "message_page",
                      meta: {
                        icon: "md-notifications",
                        title: "消息中心",
                        hideInMenu: isShow("/message")
                      },
                      component: () =>
                        import("@/view/single-page/message/index.vue")
                    }
                  ]
                },
                {
                  path: "/state",
                  name: "状态管理",
                  meta: {
                    icon: "md-analytics",
                    title: "状态管理",
                    hideInMenu: isShow2([
                      "stateMonitor",
                      "alarmRecord",
                      "onlineTrend",
                      "offlineTrend"
                    ])
                  },
                  component: Main,
                  children: [
                    {
                      path: "stateMonitor",
                      name: "状态监测",
                      meta: {
                        icon: "md-arrow-dropright-circle",
                        title: "状态监测",
                        hideInMenu: isShow("stateMonitor")
                      },
                      component: () => import("@/view/state/stateMonitor.vue")
                    },
                    {
                      path: "alarmRecord",
                      name: "状态监测",
                      meta: {
                        icon: "md-arrow-dropright-circle",
                        title: "报警记录",
                        hideInMenu: true
                      },
                      component: parentView,
                      children: [
                        {
                          path: "alarmRecord",
                          name: "状态监测",
                          meta: {
                            icon: "md-arrow-dropright-circle",
                            title: "报警记录"
                          },
                          component: parentView,
                          children: [
                            {
                              path: "alarmRecord",
                              name: "报警记录",
                              meta: {
                                icon: "md-arrow-dropright-circle",
                                title: "报警记录"
                              },
                              component: () =>
                                import(
                                  "@/view/state/alarmRecord/alarmRecord.vue"
                                )
                            }
                          ]
                        }
                      ]
                    },
                    {
                      path: "onlineTrend",
                      name: "在线趋势分析",
                      meta: {
                        icon: "md-arrow-dropright-circle",
                        title: "在线趋势分析",
                        hideInMenu: isShow("onlineTrend")
                      },
                      component: () => import("@/view/state/onlineTrend.vue")
                    },
                    {
                      path: "offlineTrend",
                      name: "离线趋势分析",
                      meta: {
                        icon: "md-arrow-dropright-circle",
                        title: "离线趋势分析",
                        hideInMenu: isShow("offlineTrend")
                      },
                      component: () => import("@/view/state/offlineTrend.vue")
                    },
                    {
        path: 'tab',
        name: '离线趋势分析',
        meta: {
          icon: 'md-arrow-dropright-circle',
          title: '离线趋势分析',
          hideInMenu:true
        },
        component: parentView,
        children:[
          {
            path: 'tab2',
            name: '离线趋势分析',
            meta: {
              icon: 'md-arrow-dropright-circle',
              title: '离线趋势分析',
              hideInMenu: false
            },
            component: () => import('@/view/state/tab/tab2.vue')
          },
          {
            path: 'tab3',
            name: '离线趋势分析',
            meta: {
              icon: 'md-arrow-dropright-circle',
              title: '离线趋势分析',
              hideInMenu: false
            },
            component: () => import('@/view/state/tab/tab3.vue')
          },
          {
            path: 'tab4',
            name: '离线趋势分析',
            meta: {
              icon: 'md-arrow-dropright-circle',
              title: '离线趋势分析',
              hideInMenu: false
            },
            component: () => import('@/view/state/tab/tab4.vue')
          },
          {
            path: 'tab5',
            name: '离线趋势分析',
            meta: {
              icon: 'md-arrow-dropright-circle',
              title: '离线趋势分析',
              hideInMenu: false
            },
            component: () => import('@/view/state/tab/tab5.vue')
          }
        ]
      }
                  ]
                },
                {
                  path: "/runManage",
                  name: "运行管理",
                  meta: {
                    icon: "md-desktop",
                    title: "运行管理",
                    hideInMenu: isShow2([
                      "nowState",
                      "stateWait",
                      "stateRecord"
                    ])
                  },
                  component: Main,
                  children: [
                    {
                      path: "nowState",
                      name: "机组当前状态",
                      meta: {
                        icon: "md-arrow-dropright-circle",
                        title: "机组当前状态",
                        hideInMenu: isShow("nowState")
                      },
                      component: () => import("@/view/runManage/nowState.vue")
                    },
                    {
                      path: "stateWait",
                      name: "机组状态待办",
                      meta: {
                        icon: "md-arrow-dropright-circle",
                        title: "机组状态待办",
                        hideInMenu: isShow("stateWait")
                      },
                      component: () => import("@/view/runManage/stateWait.vue")
                    },
                    {
                      path: "stateRecord",
                      name: "机组状态记录",
                      meta: {
                        icon: "md-arrow-dropright-circle",
                        title: "机组状态记录",
                        hideInMenu: isShow("stateRecord")
                      },
                      component: () =>
                        import("@/view/runManage/stateRecord.vue")
                    }
                  ]
                },
                {
                  path: "/problem",
                  name: "问题管理",
                  meta: {
                    icon: "ios-bug",
                    title: "问题管理",
                    hideInMenu: isShow2(["eventRecord", "tefectTracking"])
                  },
                  component: Main,
                  children: [
                    {
                      path: "eventRecord",
                      name: "事件记录",
                      meta: {
                        icon: "md-arrow-dropright-circle",
                        title: "事件记录",
                        hideInMenu: isShow("eventRecord")
                      },
                      component: () => import("@/view/problem/eventRecord.vue")
                    },
                    {
                      path: "tefectTracking",
                      name: "问题跟踪",
                      meta: {
                        icon: "md-arrow-dropright-circle",
                        title: "问题跟踪",
                        hideInMenu: isShow("tefectTracking")
                      },
                      component: () =>
                        import("@/view/problem/tefectTracking.vue")
                    }
                  ]
                },
                {
                  path: "/test",
                  name: "试验管理",
                  meta: {
                    icon: "md-flask",
                    title: "试验管理",
                    hideInMenu: isShow2(["testPlan", "testCheck", "testRecord"])
                  },
                  component: Main,
                  children: [
                    {
                      path: "testPlan",
                      name: "试验计划",
                      meta: {
                        icon: "md-arrow-dropright-circle",
                        title: "试验计划",
                        hideInMenu: isShow("testPlan")
                      },
                      component: () => import("@/view/test/testPlan.vue")
                    },
                    {
                      path: "testCheck",
                      name: "启动前检查记录",
                      meta: {
                        icon: "md-arrow-dropright-circle",
                        title: "启动前检查记录",
                        hideInMenu: isShow("testCheck")
                      },
                      component: () => import("@/view/test/testCheck.vue")
                    },
                    {
                      path: "testRecord",
                      name: "试验记录",
                      meta: {
                        icon: "md-arrow-dropright-circle",
                        title: "试验记录",
                        hideInMenu: isShow("testRecord")
                      },
                      component: () => import("@/view/test/testRecord.vue")
                    }
                  ]
                },
                {
                  path: "/repair",
                  name: "维修管理",
                  meta: {
                    icon: "md-build",
                    title: "维修管理",
                    hideInMenu: isShow2(["repairPlan", "repairRecord"])
                  },
                  component: Main,
                  children: [
                    {
                      path: "repairPlan",
                      name: "维修计划",
                      meta: {
                        icon: "md-arrow-dropright-circle",
                        title: "维修计划",
                        hideInMenu: isShow("repairPlan")
                      },
                      component: () => import("@/view/repair/repairPlan.vue")
                    },
                    {
                      path: "repairRecord",
                      name: "维修记录",
                      meta: {
                        icon: "md-arrow-dropright-circle",
                        title: "维修记录",
                        hideInMenu: isShow("repairRecord")
                      },
                      component: () => import("@/view/repair/repairRecord.vue")
                    }
                  ]
                },
                {
                  path: "/base",
                  name: "基础数据",
                  meta: {
                    icon: "md-globe",
                    title: "基础数据",
                    hideInMenu: isShow2([
                      "unitFile",
                      "deviceClass",
                      "fileManage"
                    ])
                  },
                  component: Main,
                  children: [
                    {
                      path: "unitFile",
                      name: "机组档案",
                      meta: {
                        icon: "md-arrow-dropright-circle",
                        title: "机组档案",
                        hideInMenu: isShow("unitFile")
                      },
                      component: () => import("@/view/base/unitFile.vue")
                    },
                    {
                      path: "unitFileDetail",
                      name: "机组档案详情",
                      meta: {
                        icon: "md-arrow-dropright-circle",
                        title: "机组档案详情",
                        hideInMenu: true
                      },
                      component: () => import("@/view/base/unitFileDetail.vue")
                    },
                    {
                      path: "deviceClass",
                      name: "设备分类",
                      meta: {
                        icon: "md-arrow-dropright-circle",
                        title: "设备分类",
                        hideInMenu: isShow("deviceClass")
                      },
                      component: () => import("@/view/base/deviceClass.vue")
                    },
                    {
                      path: "fileManage",
                      name: "文件管理",
                      meta: {
                        icon: "md-arrow-dropright-circle",
                        title: "文件管理",
                        hideInMenu: isShow("fileManage")
                      },
                      component: () => import("@/view/base/fileManage.vue")
                    }
                  ]
                },
                {
                  path: "/search",
                  name: "搜索结果",
                  meta: {
                    hideInMenu: true
                  },
                  component: Main,
                  children: [
                    {
                      path: "searchResult",
                      name: "搜索结果",
                      meta: {
                        icon: "md-arrow-dropright-circle",
                        title: "搜索结果",
                        hideInMenu: isShow("/search")
                      },
                      component: () => import("@/view/search/searchResult.vue")
                    }
                  ]
                },
                {
                  path: "/feed",
                  name: "经验反馈",
                  meta: {
                    hideInBread: true,
                    hideInMenu: isShow("/feedback")
                  },
                  component: Main,
                  children: [
                    {
                      path: "/feedback",
                      name: "经验反馈",
                      meta: {
                        icon: "md-list-box",
                        title: "经验反馈",
                        hideInMenu: isShow("/feedback")
                      },
                      component: () => import("@/view/feedback/feedback.vue")
                    }
                  ]
                },
                {
                  path: "/member",
                  name: "个人中心",
                  meta: {
                    icon: "md-person",
                    title: "个人中心",
                    hideInMenu: isShow2(["workWait"])
                  },
                  component: Main,
                  children: [
                    {
                      path: "workWait",
                      name: "工作待办",
                      meta: {
                        icon: 'md-person',
                        title: "工作待办",
                        hideInMenu: isShow("workWait")
                      },
                      component: () => import("@/view/member/workWait.vue")
                    }
                  ]
                },
                {
                  path: "/system",
                  name: "系统管理",
                  meta: {
                    icon: "md-settings",
                    title: "系统管理",
                    hideInMenu: isShow2([
                      "role",
                      "user",
                      "middleware",
                      "data",
                      "dict"
                    ])
                  },
                  component: Main,
                  children: [
                    {
                      path: "role",
                      name: "角色管理",
                      meta: {
                        icon: "md-arrow-dropright-circle",
                        title: "角色管理",
                        hideInMenu: isShow("role")
                      },
                      component: () => import("@/view/system/role.vue")
                    },
                    {
                      path: "user",
                      name: "用户管理",
                      meta: {
                        icon: "md-arrow-dropright-circle",
                        title: "用户管理",
                        hideInMenu: isShow("user")
                      },
                      component: () => import("@/view/system/user.vue")
                    },
                    {
                      path: "middleware",
                      name: "中间件管理",
                      meta: {
                        icon: "md-arrow-dropright-circle",
                        title: "中间件管理",
                        hideInMenu: isShow("middleware")
                      },
                      component: () => import("@/view/system/middleware.vue")
                    },
                    {
                      path: "data",
                      name: "指标数据维护",
                      meta: {
                        icon: "md-arrow-dropright-circle",
                        title: "指标数据维护",
                        hideInMenu: isShow("data")
                      },
                      component: () => import("@/view/system/data.vue")
                    },
                    {
                      path: "dict",
                      name: "字典表管理",
                      meta: {
                        icon: "md-arrow-dropright-circle",
                        title: "字典表管理",
                        hideInMenu: isShow("dict")
                      },
                      component: () => import("@/view/system/dict.vue")
                    }
                  ]
                }
              ];
              function isShow(path) {
                if (map1.indexOf(path) != -1) {
                  return true;
                } else {
                  return false;
                }
              }
              function isShow2(path) {
                let patharry = path;
                return patharry.every(val => map1.includes(val));
              }
              that.$router.addRoutes(newroutes);
              for(var i=0;i<newroutes.length;i++){
                that.$router.options.routes.push(newroutes[i])
              }

              console.log(that.$router)
              localStorage.setItem("qxmenu", JSON.stringify(map1));
              this.$router.push({
                name: this.$config.homeName
              });
            }
          });


        } else {
          this.$Message.info(res.message);
        }
      });
    }
  }
};
</script>

<style></style>
